import { IResizeEvent } from "./DefineData";
import ViewOrientation, { EOrientation } from "./ViewOrientation";
import Watcher from "./Watcher";
const { ccclass, property } = cc._decorator;

/*
 * 节点适配全屏
 *
 *
 * 程序猿:
 *   Geek7
 * 最后修改日期:
 *    2021/09/30
 */
@ccclass
export default class FitScreen extends cc.Component {


    @property([cc.Node])
    fitObjs: cc.Node[] = [];

    onLoad() {

        const fitObjs = this.fitObjs;
        Watcher.on(ViewOrientation.ON_VIEW_RESIZE, this, (e: IResizeEvent) => {
            for (let obj of fitObjs) {
                let s = obj.width / obj.height;
                e.dir == EOrientation.PORTRAIT && obj.setContentSize(s * e.size.height, e.size.height);
                e.dir == EOrientation.LANDSCAPE && obj.setContentSize(e.size.width, e.size.width / s);
            }
        });
    }
}
